﻿#include<iostream>
using namespace std;
class Person {
public:
	virtual void BuyTicket(int a = 0) { cout << "买票-全价" << a << endl; }
	void func2() {}
	virtual void func3() {}
};
	 
class Student : public Person {
    public:
		virtual void BuyTicket(int b = 1) { cout << "买票-半价" << b << endl; }
	    virtual void func3() {}
	};
	
	void Func(Person& ptr)
	{
		// 这里可以看到虽然都是Person指针Ptr在调用BuyTicket
		// 但是跟ptr没关系，而是由ptr指向的对象决定的。
		ptr.BuyTicket();
	}
	
	int main()
	{
		Person ps;       
		Student st;
		Func(ps);
		Func(st);
	
		st.BuyTicket();
	
		return 0;
	}

//class A
//{
//public:
//	 ~A()
//	{
//		cout << "~A()" << endl;
//	}
//};
//class B : public A {
//public:
//	~B()
//	{
//		cout << "~B()->delete:" << _p << endl;
//		delete _p;
//	}
//protected:
//	int* _p = new int[10];
//};
//// 只有派⽣类Student的析构函数重写了Person的析构函数，下⾯的delete对象调⽤析构函数，才能
////构成多态，才能保证p1和p2指向的对象正确的调⽤析构函数。
//int main()
//{
//	A* p1 = new A;
//	A* p2 = new B;
//	delete p1;
//	delete p2;
//	return 0;
//}



//class Car
//{
//public:
//	virtual void Drive() = 0;
//};
//class Benz :public Car
//{
//public:
//	virtual void Drive()
//	{
//		cout << "Benz-舒适" << endl;
//	}
//};
//class BMW :public Car
//{
//public:
//	virtual void Drive()
//	{
//		cout << "BMW-操控" << endl;
//	}
//};
//int main()
//{
//	// 编译报错：error C2259: “Car”: ⽆法实例化抽象类 
//	//Car car;
//	Car* pBenz = new Benz;
//	pBenz->Drive();
//	Car* pBMW = new BMW;
//	pBMW->Drive();
//	return 0;
//}
